// 基于Simon Broggi的Gist修改，适配HDRP管线
// Helper for reading HDRP Main Light + Additional Lights

#ifndef CUSTOM_LIGHT_NODE_HDRP
#define CUSTOM_LIGHT_NODE_HDRP

// 尝试不同的HDRP路径引用方式
#if defined(HDRP_PIPELINE)
    #if UNITY_VERSION >= 202030
        #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/Lighting.hlsl"
    #else
        #include "Packages/com.unity.render-pipelines.high-definition/ShaderLibrary/Lighting.hlsl"
    #endif
#endif

void GetAdditionalLightData_float(in uint index, in float3 worldPosition, out half3 direction, out half3 color, out half distanceAttenuation, out half shadowAttenuation)
{
#ifdef SHADERGRAPH_PREVIEW
    direction = half3(0.3, 0.8, 0.6);
    color = half3(1, 1, 1);
    distanceAttenuation = 1.0;
    shadowAttenuation = 1.0;
#else
    direction = float3(0, 1, 0);
    color = 0.0;
    distanceAttenuation = 0.0;
    shadowAttenuation = 0.0;

    #if defined(HDRP_PIPELINE) && defined(LIGHTING_INCLUDED)
        int lightCount = GetAdditionalLightsCount();
        if (index < lightCount)
        {
            LightData lightData = GetAdditionalLight(index, worldPosition);
            direction = lightData.direction;
            color = lightData.color;
            distanceAttenuation = lightData.attenuation;
            shadowAttenuation = lightData.shadowAttenuation;
        }
    #endif
#endif
}

void GetMainLightData_float(out half3 direction, out half3 color, out half distanceAttenuation, out half shadowAttenuation)
{
#ifdef SHADERGRAPH_PREVIEW
    direction = half3(0.3, 0.8, 0.6);
    color = half3(1, 1, 1);
    distanceAttenuation = 1.0;
    shadowAttenuation = 1.0;
#else
    direction = float3(0, 1, 0);
    color = 0.0;
    distanceAttenuation = 0.0;
    shadowAttenuation = 0.0;

    #if defined(HDRP_PIPELINE) && defined(LIGHTING_INCLUDED)
        LightData mainLightData = GetMainLight();
        direction = mainLightData.direction;
        color = mainLightData.color;
        distanceAttenuation = mainLightData.attenuation;
        shadowAttenuation = mainLightData.shadowAttenuation;
    #endif
#endif
}
#endif